package com.dingreading.cloud.web.service.impl;

import com.dingreading.cloud.web.entity.ReadInterestMember;
import com.dingreading.cloud.web.entity.table.ReadInterestMemberTableDef;
import com.dingreading.cloud.web.mapper.ReadInterestMemberMapper;
import com.dingreading.cloud.web.service.ReadInterestMemberService;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryMethods;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2024-09-11
 */
@Service
public class ReadInterestMemberServiceImpl extends BaseServiceImpl<ReadInterestMemberMapper, ReadInterestMember, ReadInterestMemberTableDef> implements ReadInterestMemberService {

    @Override
    protected ReadInterestMemberTableDef getTable() {
        return ReadInterestMemberTableDef.readInterestMember;
    }

    @Override
    public ReadInterestMember getLastData(String memberUid) {
        QueryWrapper wrapper = QueryWrapper.create()
                .select(QueryMethods.max(table.id))
                .from(table)
                .where(table.memberUid.eq(memberUid));

        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.memberUid.eq(memberUid))
                .and(table.id.eq(wrapper));
        return getMapper().selectOneByCondition(condition);
    }

}
